package org.kabeja.dxf.entity;

import org.kabeja.dxf.helpers.Point;

/**
 * @author shutao
 * @since 2022/4/24 16:34
 */
public class Bounds {
    protected double max_x = Double.NEGATIVE_INFINITY;
    protected double min_x = Double.POSITIVE_INFINITY;
    protected double max_y = Double.NEGATIVE_INFINITY;
    protected double min_y = Double.POSITIVE_INFINITY;
    protected double max_z = Double.NEGATIVE_INFINITY;
    protected double min_z = Double.POSITIVE_INFINITY;
    protected boolean set = true;

    public Bounds() {
    }

    public Bounds(double var1, double var3, double var5, double var7, double var9, double var11) {
        this.max_x = var1;
        this.min_x = var3;
        this.max_y = var5;
        this.min_y = var7;
        this.max_z = var9;
        this.min_z = var11;
    }

    public Bounds(double var1, double var3, double var5, double var7) {
        this.max_x = var1;
        this.min_x = var3;
        this.max_y = var5;
        this.min_y = var7;
    }

    public Bounds(Bounds var1) {
        this.max_x = var1.getMaximumX();
        this.min_x = var1.getMinimumX();
        this.max_y = var1.getMaximumY();
        this.min_y = var1.getMinimumY();
        this.max_z = var1.getMaximumZ();
        this.min_z = var1.getMinimumZ();
    }

    public double getMaximumX() {
        return this.max_x;
    }

    public void setMaximumX(double var1) {
        this.max_x = var1;
    }

    public double getMaximumY() {
        return this.max_y;
    }

    public void setMaximumY(double var1) {
        this.max_y = var1;
    }

    public double getMinimumX() {
        return this.min_x;
    }

    public void setMinimumX(double var1) {
        this.min_x = var1;
    }

    public double getMinimumY() {
        return this.min_y;
    }

    public void setMinimumY(double var1) {
        this.min_y = var1;
    }

    public double getMinimumZ() {
        return this.min_z;
    }

    public void setMinimumZ(double var1) {
        this.min_z = var1;
    }

    public double getMaximumZ() {
        return this.max_z;
    }

    public void setMaximumZ(double var1) {
        this.max_z = var1;
    }

    public void addToBounds(Bounds var1) {
        if (var1.getMaximumX() > this.getMaximumX()) {
            this.setMaximumX(var1.getMaximumX());
        }

        if (var1.getMaximumY() > this.getMaximumY()) {
            this.setMaximumY(var1.getMaximumY());
        }

        if (var1.getMaximumZ() > this.getMaximumZ()) {
            this.setMaximumZ(var1.getMaximumZ());
        }

        if (var1.getMinimumX() < this.getMinimumX()) {
            this.setMinimumX(var1.getMinimumX());
        }

        if (var1.getMinimumY() < this.getMinimumY()) {
            this.setMinimumY(var1.getMinimumY());
        }

        if (var1.getMinimumZ() < this.getMinimumZ()) {
            this.setMinimumZ(var1.getMinimumZ());
        }

    }

    public void addToBounds(double var1, double var3, double var5) {
        if (var1 > this.getMaximumX()) {
            this.setMaximumX(var1);
        }

        if (var1 < this.getMinimumX()) {
            this.setMinimumX(var1);
        }

        if (var3 > this.getMaximumY()) {
            this.setMaximumY(var3);
        }

        if (var3 < this.getMinimumY()) {
            this.setMinimumY(var3);
        }

        if (var5 < this.getMinimumZ()) {
            this.setMinimumZ(var5);
        }

        if (var5 > this.getMaximumZ()) {
            this.setMaximumZ(var5);
        }

    }

    public void addToBounds(Point var1) {
        this.addToBounds(var1.getX(), var1.getY(), var1.getZ());
    }

    public double getWidth() {
        return Math.abs(this.getMaximumX() - this.getMinimumX());
    }

    public double getHeight() {
        return Math.abs(this.getMaximumY() - this.getMinimumY());
    }

    public double getDepth() {
        return Math.abs(this.getMaximumZ() - this.getMinimumZ());
    }

    public boolean isValid() {
        return this.max_x != -1.0D / 0.0 && this.max_y != -1.0D / 0.0 && this.min_x != 1.0D / 0.0 && this.min_y != 1.0D / 0.0 ? this.set : false;
    }

    public void setValid(boolean var1) {
        this.set = var1;
    }

    public void debug() {
        System.out.println("DEBUG Bounds");
        System.out.println("MAX_x=" + this.max_x);
        System.out.println("MAX_y=" + this.max_y);
        System.out.println("MIN_x=" + this.min_x);
        System.out.println("MIN_y=" + this.min_y);
        System.out.println("Width=" + this.getWidth() + " Height:" + this.getHeight());
    }

    public boolean contains(Bounds var1) {
        if (!(var1.getMaximumX() <= this.min_x) && !(var1.getMinimumX() >= this.max_x)) {
            return !(var1.getMaximumY() <= this.min_y) && !(var1.getMinimumY() >= this.max_y);
        } else {
            return false;
        }
    }

    public boolean contains(Point var1) {
        return this.min_x <= var1.getX() && this.max_x >= var1.getX() && this.min_y <= var1.getY() && this.max_y >= var1.getY();
    }

    public boolean enclose(Bounds var1) {
        return var1.getMaximumX() <= this.max_x && var1.getMinimumX() >= this.min_x && var1.getMaximumY() <= this.max_y && var1.getMinimumY() >= this.min_y;
    }

    @Override
    public String toString() {
        return "{(" + min_x + ", " + min_y + "), (" + max_x + ", " + max_y + ")}";
    }
}
